/*
 * @Author: lyl 2289538564@qq.com
 * @Date: 2022-04-13 16:57:25
 * @LastEditors: CemCode cemoment@aliyun.com
 * @LastEditTime: 2022-07-02 22:50:06
 * @FilePath: \vue-blog-2\src\utils\tools.js
 * @Description: 工具类
 */

// 时间戳转格式
export const formatTime = v => {
    let date = new Date(v)
    let year = fillZero(date.getFullYear())
    let month = fillZero(date.getMonth() + 1)
    let day = fillZero(date.getDate())

    function fillZero(v) {
        return v < 10 ? "0" + v : v
    }
    return `${year}-${month}-${day}`
}

// 加深或减淡颜色
export const changeColor =function(r, g, b, number) { // type 统一加的值
    const isAdd = (v, n) => v + n >= 0 && v + n <= 255 ? v + n : v // 判断是否该加或减,如 果可以加/减则返回加/减后的值，否则不变
    r = isAdd(r, number)
    g = isAdd(g, number)
    b = isAdd(b, number)
    return `rgb(${r},${g},${b})`
}